package org.lfs.config;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import org.lfs.domain.Prompt;

import javax.swing.*;

public class PromptDatabase {

    private static final String URL = "jdbc:mysql://10.0.25.150:8306/lfs";
    private static final String USER = "erdp_test";
    private static final String PASSWORD = "seres_2022_test";

    public static List<Prompt> getPromptsFromDatabase() {
        List<Prompt> prompts = new ArrayList<>();

        try (Connection connection = DriverManager.getConnection(URL, USER, PASSWORD);
             Statement statement = connection.createStatement();
             ResultSet resultSet = statement.executeQuery("SELECT type, prompt FROM prompt")) {

            while (resultSet.next()) {
                String type = resultSet.getString("type");
                String text = resultSet.getString("prompt");
                prompts.add(new Prompt(type, text));
            }

        } catch (Exception e) {
            e.printStackTrace();
            // 显示错误消息，如果需要
            JOptionPane.showMessageDialog(null, "无法从数据库加载提示词: " + e.getMessage());
        }

        return prompts;
    }
}
